/**
 * Created by wumu on 5/30/18.
 */
import Cookies from 'js-cookie'
import * as request from '../../api/user'
const user = {
    state:{
        user:{}
    },
    getters: {
        getUser: state => {
            return state.user
        }
    },
    actions:{
        Login({ commit }, userInfo) {
            return new Promise((resolve, reject) => {
                request.login(userInfo).then((response) => {
                    if(response.status == 1){
                        sessionStorage.setItem("login",1)
                    }
                    resolve(response);
                }).catch(error => {
                    reject(error);
                });
            });
        },
        FedLogOut({commit}) {
            return new Promise(resolve => {
                sessionStorage.clear()
                resolve();
            });
        },
        GetUserInfo({commit}){
            return new Promise((resolve, reject) => {
                request.getUserInfo().then((response) => {
                    resolve(response);
                }).catch(error => {
                    reject(error);
                });
            });
        },
        Logout({commit}){
            return new Promise((resolve, reject) => {
                request.logout().then((response) => {
                    resolve(response);
                }).catch(error => {
                    reject(error);
                });
            });
        }
    }
}

export default user
